var testdata;
$(document).ready(function() {
    function t() {
        total = 0, $.each($(".meal-qty"), function(t, e) {
            total += parseInt($(e).val())
        }), $(".cart .qty .value").html(total > 0 ? total : "0")
    }
    $("body").on("click", "a.cancel-modal", function() {
        var t = $(this).closest(".reveal-modal");
        t.foundation("reveal", "close")
    }), $(".button.menu-btn.browse").click(function(t) {    	
        t.preventDefault(), $("body").animate({
            scrollTop: $("#alfred").position().top - $("#hiw").height()
        })
    }), $("a.update-meal").click(function(e) {
        e.preventDefault(), meal_id = $(this).data("meal-id"), meal_qty = $("#meals_" + meal_id), action = $(this).data("action"), error = !1, "deduct" == action ? meal_qty.val() > 0 ? meal_qty.val(parseInt(meal_qty.val()) - 1) : (error = !0, alert("There's nothing below 0!")) : "add" == action ? meal_qty.val(parseInt(meal_qty.val()) + 1) : (error = !0, alert("Error occurred, unknown action")), error || $.ajax({
            url: "/cart/update",
            type: "POST",
            data: $("#meal-form").serialize(),
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            success: function(e) {
                testdata = e, "outofstock" == e.status ? (remaining_quantity = e.meals["m-" + meal_id], remaining_quantity > 0 ? (alert("You have reached the maximum amount of meals that can be purchased."), $(".num-order.meal-" + meal_id + " .value").text(e.meals["m-" + meal_id]), $("#meals_" + meal_id).val(e.meals["m-" + meal_id])) : (alert("We apologize but the meal you have added is out of stock :("), $('.action-bar[data-id="' + meal_id + '"]').html("<h6>Sold out!</h6>")), t()) : ($(".action-bar").each(function(t, e) {
                    mqty = $(e).children("input").val(), $(e).children(".num-order").children(".value").text(mqty)
                }), t())
            },
            fail: function() {
                alert("An error occurred while updating cart, please refresh the page. If the problem persists, contact us at support@grain.com.sg")
            }
        })
    }), $(".meal").each(function(t, e) {
        tabs_content = $(e).find(".tabs-content"), biggestHeight = 0, tabs_content.children(".content").each(function(t, e) {
            biggestHeight = $(e).height() > biggestHeight ? $(e).height() : biggestHeight
        }), tabs_content.children(".content").each(function(t, e) {
            $(e).height(biggestHeight)
        })
    }), $(".hiw-btn").click(function(t) {
        t.preventDefault(), $("body").scrollTop(0), $(".fixed.contain-to-grid").css("border-bottom", "1px solid #e4e6e3"), $("#hiw").css("height", $("#hiw .row").height() + 100), setTimeout(function() {
            $(".fixed.contain-to-grid").addClass("is_white")
        }, 300)
    }), $(window).scroll(function() {
        $("body").scrollTop() > $("#banner").scrollTop() + $("#banner").height() ? $(".fixed.contain-to-grid").hasClass("is_white") || $(".fixed.contain-to-grid").addClass("is_white") : $(".fixed.contain-to-grid").hasClass("is_white") ? 0 == $("#hiw").height() ? ($(".fixed.contain-to-grid").removeClass("is_white"), $(".fixed.contain-to-grid").removeAttr("style")) : $(".fixed.contain-to-grid").addClass("is_white") : $("#hiw").height() > 0 && $(".fixed.contain-to-grid").addClass("is_white"), $("body").scrollTop() >= $("#hiw .row").height() + 100 && "0px" != $("#hiw").css("height") && ($("body").scrollTop(0), $("#hiw").hide().css("height", 0), setTimeout(function() {
            $("#hiw").show()
        }, $("#hiw .row").height() + 100))
    })
});